//
//  YXOrderListViewController.m
//  跑跑快销
//
//  Created by 杨潇 on 14-5-5.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "YXOrderListViewController.h"
#import "YXCalendarView.h"
#import "YXSalesreturnViewController.h"

@interface YXOrderListViewController ()

@end

@implementation YXOrderListViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _orderListVi = [[YXOrderListView alloc] init];
    self.view = _orderListVi;
    [_orderListVi.calendarBtn addTarget:self action:@selector(touchCalendarBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_orderListVi.salesreturn addTarget:self action:@selector(touchSalereturnBtn) forControlEvents:UIControlEventTouchUpInside];
    
    _orderListVi.nameLab.text = @"测试一下夏夏夏夏夏";
    _orderListVi.dateLab.text = @"2014-05-05";
}

#pragma mark - ButtonsClick
- (void)touchCalendarBtn:(UIButton *)btn
{
    if (!_dayBackBtn) {
        UIWindow * window = [[UIApplication sharedApplication].windows objectAtIndex:0];
        _dayBackBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        _dayBackBtn.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.3];
        _dayBackBtn.frame = [UIScreen mainScreen].bounds;
        [_dayBackBtn addTarget:self action:@selector(touchDayBackBtn) forControlEvents:UIControlEventTouchUpInside];
        [window addSubview:_dayBackBtn];
        
        YXCalendarView * dayCalendar = [[YXCalendarView alloc] initWithFrame:CGRectMake(0, btn.frame.origin.y + btn.frame.size.height + STARTY, 320, 325) withBlock:^(NSString * str) {
            _orderListVi.dateLab.text = str;
            _dayBackBtn.hidden = YES;
        }];
        [_dayBackBtn addSubview:dayCalendar];
    }
    _dayBackBtn.hidden = NO;
}

- (void)touchDayBackBtn
{
    _dayBackBtn.hidden = YES;
}

- (void)touchSalereturnBtn
{
    YXSalesreturnViewController * salesreturnVC = [[YXSalesreturnViewController alloc] init];
    salesreturnVC.title = @"退货单列表";
    salesreturnVC.nameStr = _orderListVi.nameLab.text;
    salesreturnVC.dateStr = _orderListVi.dateLab.text;
    [self setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:salesreturnVC animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
